package com.modularity.common.utils.managers.manager;

public class UrlParseManager {

    private UrlParseManager() {
        throw new UnsupportedOperationException("u can't instantiate me...");
    }

    /**
     * @param urlStr    url字符串。
     * @param paramName 指定参数名称。
     */
    public static String readValueFromUrlStrByParamName(String urlStr, String paramName) {
        if (urlStr != null && urlStr.length() > 0) {
            int index = urlStr.indexOf("?");
            String temp = (index >= 0 ? urlStr.substring(index + 1) : urlStr);
            String[] keyValue = temp.split("&");
            String destPrefix = paramName + "=";
            for (String str : keyValue) {
                if (str.indexOf(destPrefix) == 0) {
                    return str.substring(destPrefix.length());
                }
            }
        }
        return "";
    }
}
